home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
yerk
/
mps231ss.hqx
/
Mops source
/
System source
/
extras
< prev
next >
Wrap
Text File
|
1992-09-12
|
2KB
|
51 lines
\ ======== Extensions to control structures ========
\ Here is another keyed CASE. Each test value or range is compiled into
\ a pair of 2-byte entries in a table. Compilation is turned off and on
\ while getting the test values, which are evaluated at compile time. This
\ is slightly less flexible than Eaker's CASE, but is faster and more
\ compact. It is also adequate for the majority of keyed case needs.
\ When you want a positional case, SELECT{ is still the best.
:code (CASE) \ ( n -- )
loc
POP D0 ; Test value to D0
MOVE (A7),A0 ; A0 -> rtn addr
MOVE A0,A1
ADD.W (A1),A1 ; Case table addr to A1
ADD.W 2(A0),A0 ; A0 -> byte after case table
MOVE A0,(A7) ; Replace rtn addr for exit at
; stub end
MOVE.W (A1)+,D1 ; # entries in table to D1 (lo)
SUBQ.W #1,D1 ; Set up for loop
loop CMP.W (A1)+,D0 ; Test against lo value in table
BGE.S tryhi ; OK - go and try the high value
ADDQ #4,A1 ; No - skip hi val and stub offset
looptst DBRA D1,loop ; loop
PUSH D0 ; Fell thru - push test value
; again
BRA.S goto ; and goto default.
tryhi CMP.W (A1)+,D0 ; Test against hi value in table
BLE.S goto ; OK - go to corresponding action
; stub
ADDQ #2,A1 ; No - increment table pointer
BRA.S looptst ; and loop
goto SUB.W (A1),A1 ; Get action stub addr
JMP (A1) ; Go there
;code
window DW \ For display of source text during debugging
from EXTRASMOD
import{ sm bg l rl cl fm need +log -log (create_log) (write_log)
case[ ]=> ], range]=> range], default=> ]case
locate_src addr>curs redraw use_module
1up 1dn 1lft 1rt home end defnup defndn selectdw
prof_str }
:f CREATE_LOG (create_log) ;f
:f WRITE_LOG (write_log) ;f